#! /bin/bash

dir=$(cd "$(dirname "$0")"; pwd)
proj_dir=`dirname $dir`
hexo_dir="$proj_dir/export/mynote"
source_dir=$hexo_dir/source/_posts

copy_res() {
    cd $proj_dir
    res_dirs=`find . -path ./export -prune -o -name ".*" -type d`
    # find will ignore hidden dirs, so .git will not show
    for dir in $res_dirs; do
        if test "$dir" = '.'; then
            continue
        fi
        if test "$dir" = '..'; then
            continue
        fi
        basename=$(basename $dir)
        target_dir=$hexo_dir/public/$(dirname $dir)/${basename:1}
        if test ! -d $target_dir; then
            mkdir -p $target_dir
        fi
        for ele in "$dir"/*; do
            if test -f $ele; then
                cp $ele $target_dir
            fi
        done
    done
}

copy_res
